package LeetCode热题HOT100;

public class p48旋转图像 {
    public void rotate(int[][] matrix) {
        if (matrix==null||matrix.length==0) {
            return;
        }
        //实现数组顺时针旋转90度，则先沿对角线交换元素+270，再左右翻转-180
        //对角线翻转
        int row=matrix.length;
        int column=matrix[0].length;
        for (int i = 0; i <row; i++) {
            for (int j = i; j <column; j++) {
                if (i==j) continue;
                int tmp=matrix[i][j];
                matrix[i][j]=matrix[j][i];
                matrix[j][i]=tmp;
            }
        }

        //左右翻转
        for (int i = 0; i <row; i++) {
            for (int j = 0; j <column/2; j++) {
                int tmp=matrix[i][j];
                matrix[i][j]=matrix[i][column-1-i];
                matrix[i][column-1-i]=tmp;
            }
        }
    }
}
